<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选查询</span>
                <el-button
                        style="float:right"
                        type="primary"
                        @click="handleSearchList()"
                        size="small">
                    查询结果
                </el-button>
                <el-button
                        style="float:right;margin-right: 15px"
                        @click="handleResetSearch()"
                        size="small">
                    重置
                </el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="订单编号：">
                        <el-input v-model="listQuery.orderSn" class="input-width" placeholder="订单编号"></el-input>
                    </el-form-item>
                    <el-form-item label="金额范围：">
                        <el-input v-model="listQuery.minAmount" class="input-width" placeholder="最小金额"></el-input>
                        -
                        <el-input v-model="listQuery.maxAmount" class="input-width" placeholder="最大金额"></el-input>
                    </el-form-item>
                    <el-form-item label="对账状态：">
                        <el-select v-model="listQuery.checkStatus" class="input-width" placeholder="全部" clearable>
                            <el-option v-for="item in statusOptions"
                                       :key="item.value"
                                       :label="item.label"
                                       :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
        </el-card>
        <div class="table-container">
            <el-table ref="orderTable"
                      :data="list"
                      style="width: 100%;"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading" border>
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <!--                <el-table-column label="编号" width="80" align="center">-->
                <!--                    <template slot-scope="scope">{{scope.row.id}}</template>-->
                <!--                </el-table-column>-->
                <el-table-column label="订单编号" width="200" align="center">
                    <template slot-scope="scope">{{scope.row.orderSn}}</template>
                </el-table-column>
                <el-table-column label="订单金额" width="140" align="center">
                    <template slot-scope="scope">￥{{scope.row.orderAmount}}</template>
                </el-table-column>
                <el-table-column label="支付方式" width="120" align="center">
                    <template slot-scope="scope">{{scope.row.payType | formatPayType}}</template>
                </el-table-column>
                <el-table-column label="支付时间" width="200" align="center">
                    <template slot-scope="scope">{{scope.row.payTime | formatCreateTime}}</template>
                </el-table-column>
                <el-table-column label="对账人员" width="140" align="center">
                    <template slot-scope="scope">{{scope.row.checkMan}}</template>
                </el-table-column>
                <el-table-column label="对账时间" width="180" align="center">
                    <template slot-scope="scope">{{scope.row.checkTime| formatCreateTime}}</template>
                </el-table-column>
                <el-table-column label="状态" width="120" align="center">
                    <template slot-scope="scope">{{scope.row.checkStatus | formatStatus}}</template>
                </el-table-column>
                <el-table-column label="操作" width="155" align="center">
                    <template slot-scope="scope">
                        <el-button
                                size="mini"
                                @click="handleViewOrder(scope.$index, scope.row)">查看订单
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pagination-container">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes,prev, pager, next,jumper"
                    :current-page.sync="listQuery.pageNum"
                    :page-size="listQuery.pageSize"
                    :page-sizes="[5,10,15]"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    import {checkList, checkOrderDetail} from '@/api/order'
    import {formatDate} from '@/utils/date';

    const defaultListQuery = {
        pageNum: 1,
        pageSize: 10,
        orderSn: null,
        checkStatus: null,
        minAmount: null,
        maxAmount: null,
    };
    export default {
        name: "orderList",
        components: {},
        data() {
            return {
                listQuery: Object.assign({}, defaultListQuery),
                listLoading: true,
                list: null,
                total: null,
                multipleSelection: [],
                statusOptions: [
                    {
                        label: '未对账',
                        value: 0
                    },
                    {
                        label: '已对账',
                        value: 1
                    },
                    {
                        label: '异常',
                        value: 2
                    },
                ],
            }
        },
        created() {
            this.getList();
        },
        filters: {
            formatCreateTime(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
            },
            formatPayType(value) {
                if (value === 2) {
                    return '支付宝';
                } else if (value === 1) {
                    return '微信';
                }
            },
            formatStatus(value) {
                if (value === 0) {
                    return '未对账';
                } else if (value === 1) {
                    return '已对账';
                } else if (value === 2) {
                    return '异常';
                }
            },
        },
        methods: {
            handleResetSearch() {
                this.listQuery = Object.assign({}, defaultListQuery);
            },
            handleSearchList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleViewOrder(index, row) {
                this.$router.push({path: '/finance/orderDetail', query: {id: row.orderId}})
            },
            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            getList() {
                this.listLoading = true;
                checkList(this.listQuery).then(response => {
                    this.listLoading = false;
                    this.list = response.data.records;
                    this.total = response.data.total;
                });
            },
        }
    }
</script>
<style scoped>
    .input-width {
        width: 203px;
    }
</style>


